package com.common_used_class._01string;

/**
 * @Author WaveHi
 * @Date 9/8/2021 下午 1:09
 * @Version 1.0
 * @Contact HJBWaveHi@163.com
 * @Description String类的使用
 */
public class TestString {

    public static void main(String[] args) {

        //获取供测试使用的字符串
        String s1 = "Wow!";
        String s2 = "OK!";
        String s3 = "I feel good.";
        String s5 = "  Yes! ";

        //常用方法
        //1.intern() 返回字符串的规范表示形式
        String s4 = ("a" + "b").intern();

        //2.int length() 返回字符串的长度
        System.out.println("The length of s1 is  " + s1.length());

        //3.char charAt(int index) 返回指定索引位置的字符
        System.out.println("The char of " + 2 + " index is " + s1.charAt(2));

        //4.boolean isEmpty() 判断字符串是否为空字符串
        System.out.println("Whether is s1 empty string :" + s1.isEmpty());
 
        //5.String toUpperCase() 返回字符串的大写形式
        System.out.println("The uppercase of s1 is " + s1.toUpperCase());

        //6.String toLowerCase() 返回字符串的小写形式
        System.out.println("The lowercase of s1 is"  + s1.toLowerCase());

        //7.String trim() 返回一个字符串副本，忽略前导空白和尾部空白
        System.out.println("After being removed blank after anf before,the Sting is :" + s5.trim());

        //8.boolean equals(Object anObject) 与另一个字符串进行判断实体信息是否相同
        System.out.println("Is s1 the same string with s2 :" + s1.equals(s2));

        //9.boolean equalsIgnoredCase(String anString) 忽略大小写与另一个字符串比较字符串的实体信息
        System.out.println("Is s1 similar with s2:" + s1.equalsIgnoreCase(s2));

        //10.String concat(String anotherString) 连接字符串，等同于“+”
        System.out.println("Link s1 with s2 equals :" + s1.concat(s2));

        //11.int comparedTo(String anotherString) 根据自然排序比较两个字符串的大小
        System.out.println("What is  the size of s1-relationship with s2  ?:" + s1.compareTo(s2));

        //12.String substring(int beginIndex) 返回一个新的字符串，该字符串是源字符串从指定位置开始截取到最后的一个子字符串
        System.out.println("The substring of s1 is :" + s1.substring(2));

        //13.String substring(int beginIndex,int endIndex) 返回一个新的字符串，该字符串为源字符串从指定开始位置到指定结束位置截取的子字符串
        System.out.println("The substring of s3 is :" + s3.substring(1, 3));

        //14.boolean endsWith(String suffix) 判断字符串是否以指定后缀结束
        System.out.println("Does s3 end with \"wq\" ?" + s3.endsWith("io"));

        //15.boolean startsWith(String prefix) 判断字符串是否以指定前缀开始
        System.out.println("Does s3 start with \"io\" ?" + s3.startsWith("io"));

        //16.boolean startsWith(String prefix,int startIndex) 判断字符串从指定位置开始的字符串是否以指定前缀开始
        System.out.println("Does s3 start with \"io\" ?" + s3.startsWith("io", 2));


    }

}
